package com.youhome.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.youhome.mapper.BShareGroupMapper;
import com.youhome.model.BShareGroup;
import com.youhome.service.ShareGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import java.util.Date;
import java.util.List;

/**
 * Created by chen365 on 2018/09/18.
 */
@Service
public class ShareGroupServiceImpl implements ShareGroupService {
    @Autowired
    private BShareGroupMapper bShareGroupMapper;

    @Override
    public int deleteByPrimaryKey(String shareId) {
        return bShareGroupMapper.deleteByPrimaryKey(shareId);
    }

    @Override
    public int insert(BShareGroup record) {
        record.setCtime(new Date());
        return bShareGroupMapper.insert(record);
    }

    @Override
    public int insertSelective(BShareGroup record) {
        record.setCtime(new Date());
        return bShareGroupMapper.insertSelective(record);
    }

    @Override
    public BShareGroup selectByPrimaryKey(String shareId) {
        return bShareGroupMapper.selectByPrimaryKey(shareId);
    }

    @Override
    public int updateByPrimaryKeySelective(BShareGroup record) {
        record.setUtime(new Date());
        return bShareGroupMapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(BShareGroup record) {
        record.setUtime(new Date());
        return bShareGroupMapper.updateByPrimaryKey(record);
    }

    @Override
    public PageInfo<BShareGroup> selectByBean(Integer pageNumber, Integer pageSize, BShareGroup record) {
        if (StringUtils.isEmpty(pageNumber) || pageNumber < 1) {
            pageNumber = 1;
        }
        if (StringUtils.isEmpty(pageSize) || pageSize < 10) {
            pageSize = 10;
        }
        PageHelper.startPage(pageNumber, pageSize);
        List<BShareGroup> bShareGroups = bShareGroupMapper.selectByBean(record);
        return new PageInfo<>(bShareGroups);
    }

    @Override
    public int deleteByShareIdAndCounselorId(BShareGroup bShareGroup) {
        return bShareGroupMapper.deleteByShareIdAndCounselorId(bShareGroup);
    }
}
